/**
 * @author focus
 */

var ImageFlicker = Class.create({
	initialize : function(leftButtonID, rightButtonID, imageContainerID, textContainerID, images){
		this.leftButton = $(leftButtonID);
		this.rightButton = $(rightButtonID);
		this.imageContainer = $(imageContainerID);
		this.textContainer = $(textContainerID);
		this.images = images;
		this.currentImage = 0;
		
		this.leftButton.observe('click', this.flickLeft.bind(this));
		this.rightButton.observe('click', this.flickRight.bind(this));
		
		this.update();
	},
	
	update : function(){
		this.imageContainer.src = this.images[this.currentImage];
		this.textContainer.update(1 + this.currentImage + " of " + this.images.length);
		if(this.images.length == 1){
			this.textContainer.hide();
			this.leftButton.hide();
			this.rightButton.hide();
		}
			
		return false;
	},
	
	flickLeft : function(){
		this.currentImage--;
		if(this.currentImage < 0){
			this.currentImage += this.images.length;
		}
		this.update();
		return false;
	},
	
	flickRight : function(){
		this.currentImage = (this.currentImage + 1) % this.images.length;
		this.update();
		return false;
	}
});

var ArtistScroller = Class.create({
	initialize: function(leftButtonID, rightButtonID, numberOfImages){
		this.leftButton = $(leftButtonID);
		this.rightButton = $(rightButtonID);
		this.number = numberOfImages;
		this.curIndex = 0;
		
		this.leftButton.observe('click', this.moveToPrevious.bind(this));
		this.rightButton.observe('click', this.moveToNext.bind(this));
		this.updateButtons();
	},
	
	moveToPrevious: function(){
		this.curIndex--;
		this.slide(true);
		this.updateButtons();
	},
	
	moveToNext: function(){
		this.curIndex++;
		this.slide(false);
		this.updateButtons();
	},
	
	slide : function(toPrevious){
		var slideX = toPrevious ? 140 : -140;
		new Effect.Move('imageBoxInside', {
			x: slideX,
			y: 0,
			transition: Effect.Transitions.sinoidal
		});		
	},
	
	updateButtons :function(){
		
		if (this.curIndex >= (this.number-5)){
			this.rightButton.hide();
		}else{
			this.rightButton.show();
		}
		if(this.curIndex > 0){
			this.leftButton.show();
		}else{
			this.leftButton.hide();
		}
		
	}
});
